<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        label{width:70px;float: left;}
    </style>
</head>
<body>
    <h2>管理员登录</h2>
    <hr>
    <p><label for="">用户名：</label><input type="text"></p>
    <p><label for="">密&nbsp;&nbsp;码 ：</label><input type="password"></p>

    <button>登录</button>
    <button>注册</button>

    <script src="../js/jquery-1.11.3.min.js"></script>
    <script>
        $("button").eq(0).click(function(){
            let username = $("input").eq(0).val()
            let password = $("input").eq(1).val()
            $.ajax({
                url:'http://jx.xuzhixiang.top/ap/api/login.php',
                type:'get',
                data:{
                    username,
                    password
                }
            }).then(res=>{
                console.log(res);
                alert(res.msg)
                if(res.code === 1){
                    localStorage.setItem("uid",res.data.id)
                    localStorage.setItem("username",username)
                    localStorage.setItem("token",res.data.token)

                    location.href = 'index.html'
                }
            })
            
        })

        //注册按钮
        $('button').eq(1).click(function(){
            location.href="register.html"
        })
    </script>
</body>
</html>